home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / CustomSolutionWizard_Files / Examples / VCPPExample / VCPPExample.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  11.4 KB  |  205 lines

  1. #include <windows.h>
  2. HINSTANCE LoadDLLFunctions(char *dllPathName);
  3.  
  4. // Define function pointer types for both RECALL and LEARNING DLLs
  5. typedef int (*NSCreateNetwork)(void *&pNeuralNetwork, int networkType);
  6. typedef int (*NSDestroyNetwork)(void *pNeuralNetwork);
  7. typedef int (*NSGetInputOutputInfo)(void *pNeuralNetwork, int &numInputs, int &numOutputs);
  8. typedef int (*NSGetResponse)(void *pNeuralNetwork, int exemplars, float *inputData, float *outputData);
  9. typedef int (*NSGetSensitivity)(void *pNeuralNetwork, int exemplars, float *inputData, float *&sensitivityData, float dither);
  10. typedef int (*NSLoadWeights)(void *pNeuralNetwork, const char *weightsPathName);
  11. typedef int (*NSSaveWeights)(void *pNeuralNetwork, const char *weightsPathName);
  12. typedef int (*NSRandomizeWeights)(void *pNeuralNetwork);
  13. typedef int (*NSResetNetwork)(void *pNeuralNetwork);
  14.  
  15. // Define function pointer types for LEARNING DLLs only
  16. typedef int (*NSTrain)(void *pNeuralNetwork, int epochs, int exemplars, float *inputData, float *desiredData, int cvExemplars, float *cvInputData, float *cvDesiredData);
  17. typedef int (*NSGetBestCost)(void *pNeuralNetwork, float &bestCost);
  18. typedef int (*NSSetBestCost)(void *pNeuralNetwork, float bestCost);
  19. typedef int (*NSGetBestWeightsPathName)(void *pNeuralNetwork, char *bestWeightsPathName, int bufferLength, int &pathNameLength);
  20. typedef int (*NSSetBestWeightsPathName)(void *pNeuralNetwork, const char *bestWeightsPathName);
  21. typedef int (*NSGetCrossValidationEnabled)(void *pNeuralNetwork, bool &crossValidationEnabled);
  22. typedef int (*NSSetCrossValidationEnabled)(void *pNeuralNetwork, bool crossValidationEnabled);
  23. typedef int (*NSGetSaveBestWeightsEnabled)(void *pNeuralNetwork, bool &saveBestWeightsEnabled);
  24. typedef int (*NSSetSaveBestWeightsEnabled)(void *pNeuralNetwork, bool saveBestWeightsEnabled);
  25. typedef int (*NSGetSaveBestWeightsForTraining)(void *pNeuralNetwork, bool &saveBestWeightsForTraining);
  26. typedef int (*NSSetSaveBestWeightsForTraining)(void *pNeuralNetwork, bool saveBestWeightsForTraining);
  27. typedef int (*NSSetAutoComputeInputNormCoeff)(void *pNeuralNetwork, bool autoComputeInputNormCoeff);
  28. typedef int (*NSGetAutoComputeInputNormCoeff)(void *pNeuralNetwork, bool &autoComputeInputNormCoeff);
  29. typedef int (*NSSetAutoComputeOutputNormCoeff)(void *pNeuralNetwork, bool autoComputeOutputNormCoeff);
  30. typedef int (*NSGetAutoComputeOutputNormCoeff)(void *pNeuralNetwork, bool &autoComputeOutputNormCoeff);
  31. typedef int (*NSRemoveInputNormalization)(void *pNeuralNetwork);
  32. typedef int (*NSRemoveOutputNormalization)(void *pNeuralNetwork);
  33. typedef int (*NSSetInputNormMin)(void *pNeuralNetwork, float inputNormMin);
  34. typedef int (*NSGetInputNormMin)(void *pNeuralNetwork, float &inputNormMin);
  35. typedef int (*NSSetInputNormMax)(void *pNeuralNetwork, float inputNormMax);
  36. typedef int (*NSGetInputNormMax)(void *pNeuralNetwork, float &inputNormMax);
  37. typedef int (*NSSetOutputNormMin)(void *pNeuralNetwork, float outputNormMin);
  38. typedef int (*NSGetOutputNormMin)(void *pNeuralNetwork, float &outputNormMin);
  39. typedef int (*NSSetOutputNormMax)(void *pNeuralNetwork, float outputNormMax);
  40. typedef int (*NSGetOutputNormMax)(void *pNeuralNetwork, float &outputNormMax);
  41. typedef int (*NSSetNormalizeInputByChannel)(void *pNeuralNetwork, bool normalizeInputByChannel);
  42. typedef int (*NSGetNormalizeInputByChannel)(void *pNeuralNetwork, bool &normalizeInputByChannel);
  43. typedef int (*NSSetNormalizeOutputByChannel)(void *pNeuralNetwork, bool normalizeOutputByChannel);
  44. typedef int (*NSGetNormalizeOutputByChannel)(void *pNeuralNetwork, bool &normalizeOutputByChannel);
  45. typedef int (*NSGetCrossValidationCostData)(void *pNeuralNetwork, float *cvCostData);
  46. typedef int (*NSGetCostData)(void *pNeuralNetwork, float *costData);
  47. typedef int (*NSGetNumberOfEpochsTrained)(void *pNeuralNetwork, int &numberOfEpochsTrained);
  48. typedef int (*NSGetEpochOfBestCost)(void *pNeuralNetwork, int &epochOfBestCost);
  49. typedef int (*NSSeedRandom)(void *pNeuralNetwork, unsigned int seed);
  50.  
  51. // Declare function pointers for both RECALL and LEARNING DLLs
  52. NSCreateNetwork createNetwork;
  53. NSDestroyNetwork destroyNetwork;
  54. NSLoadWeights loadWeights;
  55. NSSaveWeights saveWeights;
  56. NSRandomizeWeights randomizeWeights;
  57. NSResetNetwork resetNetwork;
  58. NSGetInputOutputInfo getInputOutputInfo;
  59. NSGetResponse getResponse;
  60. NSGetSensitivity getSensitivity;
  61.  
  62. // Declare function pointers for LEARNING DLLs only
  63. NSGetBestCost getBestCost;
  64. NSSetBestCost setBestCost;
  65. NSTrain train;
  66. NSGetBestWeightsPathName getBestWeightsPathName;
  67. NSSetBestWeightsPathName setBestWeightsPathName;
  68. NSGetCrossValidationEnabled getCrossValidationEnabled;
  69. NSSetCrossValidationEnabled setCrossValidationEnabled;
  70. NSGetSaveBestWeightsEnabled getSaveBestWeightsEnabled;
  71. NSSetSaveBestWeightsEnabled setSaveBestWeightsEnabled;
  72. NSGetSaveBestWeightsForTraining getSaveBestWeightsForTraining;
  73. NSSetSaveBestWeightsForTraining setSaveBestWeightsForTraining;
  74. NSSetAutoComputeInputNormCoeff setAutoComputeInputNormCoeff;
  75. NSGetAutoComputeInputNormCoeff getAutoComputeInputNormCoeff;
  76. NSSetAutoComputeOutputNormCoeff setAutoComputeOutputNormCoeff;
  77. NSGetAutoComputeOutputNormCoeff getAutoComputeOutputNormCoeff;
  78. NSRemoveInputNormalization removeInputNormalization;
  79. NSRemoveOutputNormalization removeOutputNormalization;
  80. NSSetInputNormMin setInputNormMin;
  81. NSGetInputNormMin getInputNormMin;
  82. NSSetInputNormMax setInputNormMax;
  83. NSGetInputNormMax getInputNormMax;
  84. NSSetOutputNormMin setOutputNormMin;
  85. NSGetOutputNormMin getOutputNormMin;
  86. NSSetOutputNormMax setOutputNormMax;
  87. NSGetOutputNormMax getOutputNormMax;
  88. NSSetNormalizeInputByChannel setNormalizeInputByChannel;
  89. NSGetNormalizeInputByChannel getNormalizeInputByChannel;
  90. NSSetNormalizeOutputByChannel setNormalizeOutputByChannel;
  91. NSGetNormalizeOutputByChannel getNormalizeOutputByChannel;
  92. NSGetCrossValidationCostData getCrossValidationCostData;
  93. NSGetCostData getCostData;
  94. NSGetNumberOfEpochsTrained getNumberOfEpochsTrained;
  95. NSGetEpochOfBestCost getEpochOfBestCost;
  96. NSSeedRandom seedRandom;
  97.  
  98. HINSTANCE LoadDLLFunctions(char *dllPathName)
  99. {
  100.     HINSTANCE hDLL = LoadLibrary(dllPathName);
  101.     if (hDLL)
  102.     {
  103.         // Assign function pointers for both RECALL and LEARNING DLLs
  104.         createNetwork = (NSCreateNetwork)GetProcAddress(hDLL, "createNetwork");
  105.         destroyNetwork = (NSDestroyNetwork)GetProcAddress(hDLL, "destroyNetwork");
  106.         getInputOutputInfo = (NSGetInputOutputInfo)GetProcAddress(hDLL, "getInputOutputInfo");
  107.         getResponse = (NSGetResponse)GetProcAddress(hDLL, "getResponse");
  108.         getSensitivity = (NSGetSensitivity)GetProcAddress(hDLL, "getSensitivity");
  109.         loadWeights = (NSLoadWeights)GetProcAddress(hDLL, "loadWeights");
  110.         saveWeights = (NSSaveWeights)GetProcAddress(hDLL, "saveWeights");
  111.         randomizeWeights = (NSRandomizeWeights)GetProcAddress(hDLL, "randomizeWeights");
  112.         resetNetwork = (NSResetNetwork)GetProcAddress(hDLL, "resetNetwork");
  113.  
  114.         // Assign function pointers for LEARNING DLLs only
  115.         train = (NSTrain)GetProcAddress(hDLL, "train");
  116.         getBestCost = (NSGetBestCost)GetProcAddress(hDLL, "getBestCost");
  117.         setBestCost = (NSSetBestCost)GetProcAddress(hDLL, "setBestCost");
  118.         getBestWeightsPathName = (NSGetBestWeightsPathName)GetProcAddress(hDLL, "getBestWeightsPathName");
  119.         setBestWeightsPathName = (NSSetBestWeightsPathName)GetProcAddress(hDLL, "setBestWeightsPathName");
  120.         getSaveBestWeightsEnabled = (NSGetSaveBestWeightsEnabled)GetProcAddress(hDLL, "getSaveBestWeightsEnabled");
  121.         setSaveBestWeightsEnabled = (NSSetSaveBestWeightsEnabled)GetProcAddress(hDLL, "setSaveBestWeightsEnabled");
  122.         getSaveBestWeightsForTraining = (NSGetSaveBestWeightsForTraining)GetProcAddress(hDLL, "getSaveBestWeightsForTraining");
  123.         setSaveBestWeightsForTraining = (NSSetSaveBestWeightsForTraining)GetProcAddress(hDLL, "setSaveBestWeightsForTraining");
  124.         getCrossValidationEnabled = (NSGetCrossValidationEnabled)GetProcAddress(hDLL, "getCrossValidationEnabled");
  125.         setCrossValidationEnabled = (NSSetCrossValidationEnabled)GetProcAddress(hDLL, "setCrossValidationEnabled");
  126.         setAutoComputeInputNormCoeff = (NSSetAutoComputeInputNormCoeff)GetProcAddress(hDLL, "setAutoComputeInputNormCoeff");
  127.         getAutoComputeInputNormCoeff = (NSGetAutoComputeInputNormCoeff)GetProcAddress(hDLL, "getAutoComputeInputNormCoeff");
  128.         setAutoComputeOutputNormCoeff = (NSSetAutoComputeOutputNormCoeff)GetProcAddress(hDLL, "setAutoComputeOutputNormCoeff");
  129.         getAutoComputeOutputNormCoeff = (NSGetAutoComputeOutputNormCoeff)GetProcAddress(hDLL, "getAutoComputeOutputNormCoeff");
  130.         removeInputNormalization = (NSRemoveInputNormalization)GetProcAddress(hDLL, "removeInputNormalization");
  131.         removeOutputNormalization = (NSRemoveOutputNormalization)GetProcAddress(hDLL, "removeOutputNormalization");
  132.         setInputNormMin = (NSSetInputNormMin)GetProcAddress(hDLL, "setInputNormMin");
  133.         getInputNormMin = (NSGetInputNormMin)GetProcAddress(hDLL, "getInputNormMin");
  134.         setInputNormMax = (NSSetInputNormMax)GetProcAddress(hDLL, "setInputNormMax");
  135.         getInputNormMax = (NSGetInputNormMax)GetProcAddress(hDLL, "getInputNormMax");
  136.         setOutputNormMin = (NSSetOutputNormMin)GetProcAddress(hDLL, "setOutputNormMin");
  137.         getOutputNormMin = (NSGetOutputNormMin)GetProcAddress(hDLL, "getOutputNormMin");
  138.         setOutputNormMax = (NSSetOutputNormMax)GetProcAddress(hDLL, "setOutputNormMax");
  139.         getOutputNormMax = (NSGetOutputNormMax)GetProcAddress(hDLL, "getOutputNormMax");
  140.         setNormalizeInputByChannel = (NSSetNormalizeInputByChannel)GetProcAddress(hDLL, "setNormalizeInputByChannel");
  141.         getNormalizeInputByChannel = (NSGetNormalizeInputByChannel)GetProcAddress(hDLL, "getNormalizeInputByChannel");
  142.         setNormalizeOutputByChannel = (NSSetNormalizeOutputByChannel)GetProcAddress(hDLL, "setNormalizeOutputByChannel");
  143.         getNormalizeOutputByChannel = (NSGetNormalizeOutputByChannel)GetProcAddress(hDLL, "getNormalizeOutputByChannel");
  144.         getCrossValidationCostData = (NSGetCrossValidationCostData)GetProcAddress(hDLL, "getCrossValidationCostData");
  145.         getCostData = (NSGetCostData)GetProcAddress(hDLL, "getCostData");
  146.         getNumberOfEpochsTrained = (NSGetNumberOfEpochsTrained)GetProcAddress(hDLL, "getNumberOfEpochsTrained");
  147.         getEpochOfBestCost = (NSGetEpochOfBestCost)GetProcAddress(hDLL, "getEpochOfBestCost");
  148.         seedRandom = (NSSeedRandom)GetProcAddress(hDLL, "seedRandom");
  149.  
  150.         if (!(
  151.         // Check function pointers for both RECALL and LEARNING DLLs
  152.         createNetwork &&
  153.         destroyNetwork &&
  154.         getInputOutputInfo &&
  155.         getResponse &&
  156.         getSensitivity &&
  157.         loadWeights &&
  158.         saveWeights &&
  159.         randomizeWeights &&
  160.         resetNetwork &&
  161.  
  162.         // Check function pointers for LEARNING DLLs only
  163.         train &&
  164.         getBestCost &&
  165.         setBestCost &&
  166.         getBestWeightsPathName &&
  167.         setBestWeightsPathName &&
  168.         getSaveBestWeightsEnabled &&
  169.         setSaveBestWeightsEnabled &&
  170.         getSaveBestWeightsForTraining &&
  171.         setSaveBestWeightsForTraining &&
  172.         getCrossValidationEnabled &&
  173.         setCrossValidationEnabled &&
  174.         setAutoComputeInputNormCoeff &&
  175.         getAutoComputeInputNormCoeff &&
  176.         setAutoComputeOutputNormCoeff &&
  177.         getAutoComputeOutputNormCoeff &&
  178.         removeInputNormalization &&
  179.         removeOutputNormalization &&
  180.         setInputNormMin &&
  181.         getInputNormMin &&
  182.         setInputNormMax &&
  183.         getInputNormMax &&
  184.         setOutputNormMin &&
  185.         getOutputNormMin &&
  186.         setOutputNormMax &&
  187.         getOutputNormMax &&
  188.         setNormalizeInputByChannel &&
  189.         getNormalizeInputByChannel &&
  190.         setNormalizeOutputByChannel &&
  191.         getNormalizeOutputByChannel &&
  192.         getCrossValidationCostData &&
  193.         getCostData &&
  194.         getNumberOfEpochsTrained &&
  195.         getEpochOfBestCost &&
  196.         seedRandom
  197.         ))
  198.         {
  199.             FreeLibrary(hDLL);
  200.             hDLL = 0;
  201.         }
  202.     }
  203.     return hDLL;
  204. }
  205.